package springcloud.consume.feign.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import springcloud.consume.feign.service.UserService;
import springcloud.service.model.User;

import java.util.List;

/**
 * 消费端接口，像 eureka 请求需要的服务
 */
@RestController
@Slf4j
@RefreshScope
@RequestMapping("/consume")
public class ConsumeFeignController {

    @Autowired
    private UserService userService;

    @Value("${source}")
    private String source;
    @Value("${name}")
    private String name;

    @ResponseBody
    @PostMapping("/addUser")
    public int addUser(User user){

        log.info("===============${name}=" + name);
        log.info("===============${source}=" + source);
        log.debug("===============addUser");

        int i = userService.addUser(user);
        return i;
    }

    @ResponseBody
    @GetMapping("/getUserById/{userId}")
    public User getUserById(@PathVariable("userId") Integer userId){

        log.info("===============${name}=" + name);
        log.info("===============${source}=" + source);
        log.debug("===============addUser");

        User user = userService.getUserById(userId);

        return user;
    }

    @ResponseBody
    @GetMapping("/getAll")
    public List<User> getAll(){

        log.info("===============${name}=" + name);
        log.info("===============${source}=" + source);
        log.debug("===============getAll");

        List<User> user = userService.getAll();

        return user;
    }
}



